﻿using System;
using System.Diagnostics;
using Autodesk.Revit.Attributes;
using Autodesk.Revit.DB;
using Autodesk.Revit.UI;
using YJKCodeBase.WinForm;
using YJKView;
using StructureModelDeduction.Manager;

namespace StructureModelDeduction
{
	[Transaction(TransactionMode.Manual)]
	internal class CmdStructuralModelDeduction : IExternalCommand
	{
		Result IExternalCommand.Execute(ExternalCommandData commandData, ref string message, ElementSet elements)
		{
			int num = Convert.ToInt32(commandData.Application.Application.VersionNumber);
			if (num < 2014)
			{
				message = "此功能只在Revit2014及其以上版本可用。";
				return Autodesk.Revit.UI.Result.Failed;
			}
			CmdViewType types = (CmdViewType)11;
			if (SwitchView.SetUsableView(types, commandData) != Autodesk.Revit.UI.Result.Succeeded)
			{
				return Autodesk.Revit.UI.Result.Failed;
			}
			if (CmdStructuralModelDeduction._hWndRevit == null)
			{
				Process currentProcess = Process.GetCurrentProcess();
				IntPtr mainWindowHandle = currentProcess.MainWindowHandle;
				CmdStructuralModelDeduction._hWndRevit = new WindowHandle(mainWindowHandle);
			}
			HideWarningKit @object = new HideWarningKit("模型扣减");
			commandData.Application.Application.FailuresProcessing += @object.OnFailuresProcessing;
			HideWarningKit object2 = new HideWarningKit("墙扣减");
			commandData.Application.Application.FailuresProcessing += object2.OnFailuresProcessing;
			ModelDeductionManager modelDeductionManager = new ModelDeductionManager(commandData);
			if (!modelDeductionManager.Run())
			{
				return Autodesk.Revit.UI.Result.Failed;
			}
			return Autodesk.Revit.UI.Result.Succeeded;
		}

		public static WindowHandle _hWndRevit;
	}
}
